﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BZLib.Global;
using BZLib.Flags;

namespace BZLib
{
    namespace Shots
    {
        public class ShotUpdate
        {
            public int Owner;
            public int ID;
            public Point Position;
            public Point Velocity;
            public double DelayTime;
            public TeamName Team;

            public ShotUpdate()
            {
                Owner = -1;
                ID = -1;
                Position = new Point();
                Velocity = new Point();
                DelayTime = 0;
                Team = TeamName.NoTeam;
            }

            public BinaryString Pack()
            {
                BinaryString str = new BinaryString();
                str.PackUByte((byte)Owner);
                str.PackUShort((ushort)ID);
                str.Pack(Position);
                str.Pack(Velocity);
                str.PackFloat((float)DelayTime);
                str.PackShort((short)Team);
                return str;
            }

            public BinaryString Unpack(BinaryString str)
            {
                Owner = str.UnpackUByte();
                ID = str.UnpackUShort();
                str.Unpack(Position);
                str.Unpack(Velocity);
                DelayTime = str.UnpackFloat();
                Team = (TeamName)str.UnpackShort();
                return str;
            }
        }

        public class FiringInfo : IUnpackable, IPackable
        {
            public double TimeSent;
            public ShotUpdate Shot;
            public FlagType FlagType;
            public double Lifetime;

            public FiringInfo()
            {
                TimeSent = 0;
                Shot = new ShotUpdate();
                FlagType = FlagList.Null;
                Lifetime = 0;
            }

            public BinaryString Pack()
            {
                BinaryString str = new BinaryString();
                str.PackFloat((float)TimeSent);
                str += Shot.Pack();
                str += FlagType.Pack();
                str.PackFloat((float)Lifetime);
                return str;
            }

            public BinaryString Unpack(BinaryString str)
            {
                TimeSent = str.UnpackFloat();
                str = Shot.Unpack(str);
                str = FlagType.Unpack(str, ref FlagType);
                Lifetime = str.UnpackFloat();
                return str;
            }
        }
    }
}
